﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Hangout.Web.Core.Text
{
    public class TextManipulation
    {
        public static List<string> GetAllTokens(string text)
        {
            text = text.ToLower();
            List<string> strings= text.Split(' ').ToList().Where(o => o.StartsWith("#")).ToList();


            List<string> texts = new List<string>();
            foreach (string t in strings)
            {
                texts.Add(t.TrimStart('#'));

            }

            return texts;
        }

        public static DateTime GetDateTime(string text,DateTime clientDateTime)
        {
            List<string> str = GetAllTokens(text);

            if (str.Contains("tomorrow"))
            {
                return clientDateTime.AddDays(1);
            }

            TimeSpan t=new TimeSpan();

            foreach(string s in str)
            {
                if(TimeSpan.TryParse(s,out t))
                {
                    clientDateTime = clientDateTime.Date + t;
                }
            }

            return clientDateTime;
        }
    }
}